Class Session

Summary

Fully Qualified Name: CodeIgniter\Session\Session
Implements: SessionInterface

Description

Implementation of CodeIgniter session container.

Session configuration is done through session variables and cookie related variables in app/config/App.php

Methods

Name Description Defined By
__construct() Constructor. Session
__get() Magic method to get session variables by simply calling $foo = $session->foo; Session
__isset() Magic method to check for session variables. Session
__set() Magic method to set variables in the session by simply calling $session->foo = bar; Session
destroy() Destroys the current session. Session
get() Get user data that has been set in the session. Session
getFlashKeys() Retrieve all of the keys for session data marked as flashdata. Session
getFlashdata() Retrieve one or more items of flash data from the session. Session
getTempKeys() Retrieve the keys of all session data that have been marked as temporary data. Session
getTempdata() Returns either a single piece of tempdata, or all temp data currently in the session. Session
has() Returns whether an index exists in the session array. Session
keepFlashdata() Keeps a single piece of flash data alive for one more request. Session
markAsFlashdata() Mark a session property or properties as flashdata. Session
markAsTempdata() Mark one of more pieces of data as being temporary, meaning that it has a set lifespan within the session. Session
push() Push new value onto session value that is array. Session
regenerate() Regenerates the session ID. Session
remove() Remove one or more session properties. Session
removeTempdata() Removes a single piece of temporary data from the session. Session
set() Sets user data into the session. Session
setFlashdata() Sets data into the session that will only last for a single request. Session
setTempdata() Sets new data into the session, and marks it as temporary data with a set lifespan. Session
start() Initialize the session container and starts up the session. Session
stop() Does a full stop of the session: Session
unmarkFlashdata() Unmark data in the session as flashdata. Session
unmarkTempdata() Unmarks temporary data in the session, effectively removing its lifespan and allowing it to live as long as the session does. Session

Method Details

__construct()

Constructor.

Extract configuration settings and save them here.

Parameter Name Type Description
$driver \SessionHandlerInterface
$config \Config\App

Returns:

__get()

Magic method to get session variables by simply calling $foo = $session->foo;

Parameter Name Type Description
$key string Identifier

Returns: null|string

__isset()

Magic method to check for session variables.

Different from has() in that it will validate 'session_id' as well. Mostly used by internal PHP functions, users should stick to has()

Parameter Name Type Description
$key string Identifier

Returns: bool

__set()

Magic method to set variables in the session by simply calling $session->foo = bar;

Parameter Name Type Description
$key string Identifier
$value string|array

Returns:

destroy()

Destroys the current session.

Returns:

get()

Get user data that has been set in the session.

If the property exists as "normal", returns it. Otherwise, returns an array of any temp or flash data values with the property key.

Replaces the legacy method $session->userdata();

Parameter Name Type Description
$key string Identifier

Returns: array|null The property value(s)

getFlashKeys()

Retrieve all of the keys for session data marked as flashdata.

Returns: array The property names of all flashdata

getFlashdata()

Retrieve one or more items of flash data from the session.

If the item key is null, return all flashdata.

Parameter Name Type Description
$key string Property

Returns: array|null The requested property value, or an associative array of them

getTempKeys()

Retrieve the keys of all session data that have been marked as temporary data.

Returns: array

getTempdata()

Returns either a single piece of tempdata, or all temp data currently in the session.

Parameter Name Type Description
$key string Session

Returns: mixed Session data value or null if not found.

has()

Returns whether an index exists in the session array.

Parameter Name Type Description
$key string Identifier

Returns: bool

keepFlashdata()

Keeps a single piece of flash data alive for one more request.

Parameter Name Type Description
$key array|string Property

Returns:

markAsFlashdata()

Mark a session property or properties as flashdata.

Parameter Name Type Description
$key array|string Property

Returns: bool False if any of the properties are not already set

markAsTempdata()

Mark one of more pieces of data as being temporary, meaning that it has a set lifespan within the session.

Parameter Name Type Description
$key string|array Property
$ttl int Time

Returns: bool False if any of the properties were not set

push()

Push new value onto session value that is array.

Parameter Name Type Description
$key string Identifier
$data array value

Returns: void

regenerate()

Regenerates the session ID.

Parameter Name Type Description
$destroy bool Should

Returns:

remove()

Remove one or more session properties.

If $key is an array, it is interpreted as an array of string property identifiers to remove. Otherwise, it is interpreted as the identifier of a specific session property to remove.

Parameter Name Type Description
$key string|array Identifier

Returns:

removeTempdata()

Removes a single piece of temporary data from the session.

Parameter Name Type Description
$key string Session

Returns:

set()

Sets user data into the session.

If $data is a string, then it is interpreted as a session property key, and $value is expected to be non-null.

If $data is an array, it is expected to be an array of key/value pairs to be set as session properties.

Parameter Name Type Description
$data string|array Property
$value string|array Property

Returns:

setFlashdata()

Sets data into the session that will only last for a single request.

Perfect for use with single-use status update messages.

If $data is an array, it is interpreted as an associative array of key/value pairs for flashdata properties. Otherwise, it is interpreted as the identifier of a specific flashdata property, with $value containing the property value.

Parameter Name Type Description
$data array|string Property
$value string|array Property

Returns:

setTempdata()

Sets new data into the session, and marks it as temporary data with a set lifespan.

Parameter Name Type Description
$data string|array Session
$value null Value
$ttl int Time-to-live

Returns:

start()

Initialize the session container and starts up the session.

Returns: mixed

stop()

Does a full stop of the session:

Returns:

unmarkFlashdata()

Unmark data in the session as flashdata.

Parameter Name Type Description
$key mixed Property

Returns:

unmarkTempdata()

Unmarks temporary data in the session, effectively removing its lifespan and allowing it to live as long as the session does.

Parameter Name Type Description
$key string|array Property

Returns:

Top